package com.zonski.jbots.engine.test;

import junit.framework.TestCase;

import com.zonski.jbots.engine.Rectangle;

public class RectangleTestCase extends TestCase
{
    public RectangleTestCase(String name)
    {
        super(name);
    }

    public void testContains()
    {
        Rectangle r1 = new Rectangle(0, 0, 10, 10);
        Rectangle r2 = new Rectangle(1, 1, 8, 8);
        TestCase.assertEquals(true, r1.overlaps(r2));
        TestCase.assertEquals(true, r2.overlaps(r1));
    }

    public void testNEIntersects()
    {
        Rectangle r1 = new Rectangle(0, 0, 5, 5);
        Rectangle r2 = new Rectangle(4, 4, 5, 5);
        TestCase.assertEquals(true, r1.overlaps(r2));
        TestCase.assertEquals(true, r2.overlaps(r1));
    }

    public void testNWIntersects()
    {
        Rectangle r1 = new Rectangle(0, 0, 5, 5);
        Rectangle r2 = new Rectangle(-4, 4, 5, 5);
        TestCase.assertEquals(true, r1.overlaps(r2));
        TestCase.assertEquals(true, r2.overlaps(r1));
    }

    public void testSEIntersects()
    {
        Rectangle r1 = new Rectangle(0, 0, 5, 5);
        Rectangle r2 = new Rectangle(4, -4, 5, 5);
        TestCase.assertEquals(true, r1.overlaps(r2));
        TestCase.assertEquals(true, r2.overlaps(r1));
    }

    public void testSWIntersects()
    {
        Rectangle r1 = new Rectangle(0, 0, 5, 5);
        Rectangle r2 = new Rectangle(-4, -4, 5, 5);
        TestCase.assertEquals(true, r1.overlaps(r2));
        TestCase.assertEquals(true, r2.overlaps(r1));
    }

    public void testEquals()
    {
        Rectangle r = new Rectangle(0, 0, 1, 1);
        TestCase.assertEquals(true, r.overlaps(r));
    }

    public void testSharedNorthEdge()
    {
        Rectangle r1 = new Rectangle(0, 0, 10, 10);
        Rectangle r2 = new Rectangle(2, 4, 6, 6);
        TestCase.assertEquals(true, r1.overlaps(r2));
        TestCase.assertEquals(true, r2.overlaps(r1));
    }

    public void testSharedSouthEdge()
    {
        Rectangle r1 = new Rectangle(0, 0, 10, 10);
        Rectangle r2 = new Rectangle(2, 0, 6, 6);
        TestCase.assertEquals(true, r1.overlaps(r2));
        TestCase.assertEquals(true, r2.overlaps(r1));
    }

    public void testSharedEastEdge()
    {
        Rectangle r1 = new Rectangle(0, 0, 10, 10);
        Rectangle r2 = new Rectangle(4, 2, 6, 6);
        TestCase.assertEquals(true, r1.overlaps(r2));
        TestCase.assertEquals(true, r2.overlaps(r1));
    }

    public void testSharedWestEdge()
    {
        Rectangle r1 = new Rectangle(0, 0, 10, 10);
        Rectangle r2 = new Rectangle(0, 2, 6, 6);
        TestCase.assertEquals(true, r1.overlaps(r2));
        TestCase.assertEquals(true, r2.overlaps(r1));
    }
}
